package test
{
	import _Pan3D.display3D.Display3DContainer;
	import _Pan3D.display3D.Display3DMovie;
	import _Pan3D.display3D.Display3DShadowSprite;
	import _Pan3D.display3D.Display3DSprite;
	import _Pan3D.program.Program3DManager;
	import _Pan3D.program.shaders.Md5Shader;
	import _Pan3D.program.shaders.ShadowShader;
	import _Pan3D.program.shaders.StatShader;
	import _Pan3D.texture.TextureManager;
	
	import _me.KeyControl;
	import _Pan3D.core.MathCore;
	import _me.Scene_data;
	
	import com.adobe.utils.PerspectiveMatrix3D;
	
	import flash.display3D.Context3D;
	import flash.display3D.Context3DProgramType;
	import flash.display3D.Program3D;
	import flash.events.Event;
	import flash.geom.Vector3D;
	[SWF(backgroundColor="#FFFFFF",width="1024", height="600", frameRate="60")]
	public class loadMd5 extends BaseDemo
	{
		private var _programMd5:Program3D;
		private var _groundMode:Display3DContainer;
		private var _guaiwuMd5Mode:Display3DMovie;
		public function loadMd5()
		{
			super();
			//makeScene();
		}
		override protected function makeScene():void
		{
			Scene_data._sunMatrix.identity();
			Scene_data._sunMatrix.prependTranslation(0, 0, -4000);
			Scene_data._sunMatrix.prependRotation(120, new Vector3D(1, 0, 0));
			Scene_data._sunMatrix.prependTranslation(0, 0, 0);
			var context3D : Context3D = Scene_data.context3D;
			TextureManager.getInstance().init(context3D);
			container=new Display3DContainer;
			
			//addGrounds();
			addMd5Model();
			
			
			this.addEventListener(Event.ENTER_FRAME, enterFrame);
			Scene_data.cam3D.distance = 300;
			Scene_data.focus3D.angle_y = 0;
			Scene_data.focus3D.angle_x =-30;
			
		}
		private function addGrounds():void
		{
			var context3D : Context3D = Scene_data.context3D;
			_groundMode = new Display3DContainer();
			var sp1:Display3DSprite = new Display3DSprite(context3D);
			sp1.url = "baseGround";
			_groundMode.addChild(sp1);
			container.addChild(_groundMode);
			var statShaderProgram3d:Program3D = Program3DManager.getInstance().getProgram(StatShader.STATSHADER);
			_groundMode.setProgram3D(statShaderProgram3d);
			
		}
		private function addMd5Model():void
		{
			var context3D : Context3D = Scene_data.context3D;
			_guaiwuMd5Mode = new Display3DMovie(context3D);
			_guaiwuMd5Mode.addMesh("0", "run");
			_guaiwuMd5Mode.addAnim("run", "run");
			//_guaiwuMd5Mode.addAnim("default", "default");
			_guaiwuMd5Mode.scale=6;
			container.addChild(_guaiwuMd5Mode);
			var md5Program:Program3D = Program3DManager.getInstance().getProgram(Md5Shader.MD5SHADER);
			_guaiwuMd5Mode.setProgram3D(md5Program);
	
		}
		override protected function  enterFrame(event : Event) : void {
			keyControl.upData();
			MathCore._catch_cam(Scene_data.cam3D, Scene_data.focus3D);
			//Scene_data.cam3D.toString();
			if (!Scene_data.ready ) return;
			var context : Context3D = Scene_data.context3D;
			context.clear(0, 0, 0, 1);
			projMatrix = new PerspectiveMatrix3D();
			projMatrix.perspectiveFieldOfViewRH(1, 1, 0.1, 90000);
			context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, projMatrix, true);
			container.update();
			context.present();
			
		}
	}
}